package crawler.douban;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
 * 电视剧
 * USER: lintc 【lintiancong@zhuojianchina.com】
 * DATE: 2017-09-21 09:46
 */
public class Teleplay {

    public static Movie newTeleplay(Element element) {
        Movie movie = new Movie();
        movie.setName(element.select(".title>a").text());
        movie.setUrl(element.select(".title>a").attr("href"));
        movie.setId(movie.getMovieId(movie.getUrl()));
        movie.setCommentCount(getCommentCount(element));
        movie.setStartLevel(Float.parseFloat(element.select(".rating>.rating_nums").text()));
//        movie.setDirector("");
//        movie.setActors(null);
//        movie.setReleaseDate("");
//        movie.setMovieType(null);
//        movie.setArea(null);
//        movie.setInsertTime(null);
        return movie;
    }

    public static Integer getCommentCount(Element element) {
        String commentCount = element.select(".rating>span").get(2).text();
        return Integer.parseInt(commentCount.substring(1, commentCount.indexOf("人")));
    }

    public static void main(String[] args) throws IOException {
        String url = "https://www.douban.com/doulist/3038463/?start=0&sort=seq&sub_type=";
        Document doc = Jsoup.connect(url).get();
        Elements elements = doc.select(".doulist-item");
        for (Element element : elements) {
            System.out.println(element);
            System.out.println("--------------------");
        }
    }
}
